﻿@model LeadMaster.ViewModels.ViewModelSurveys

<h1>Mapping</h1>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>

    @Html.HiddenFor(m => m.Surveys.LeadID)
    
    <div>
    <label>Select Template</label>
    </div>

    <div>
    @Html.DropDownList("LeadTemplatesID", null, new { style = "width:300px;", @class="chosen" })
    </div>

    <div class="spacer"></div>

    <div>
    <label>Mapping Ref</label>
    </div>
    <div>
    @Html.EditorFor(m => Model.Surveys.Ref)
    </div>

    <div class="spacer"></div>
    <div>
    <label>Http Post Output ?</label>
    </div>
    <div>
    @Html.EditorFor(m => Model.Surveys.HttpPost)
    </div>

    <div class="spacer"></div>
    <div>
    <label>HTTP String (include https://)</label>
    </div>
    <div>
    @Html.EditorFor(m => Model.Surveys.HTTPstring, new { @class = "largetextbox" })
    </div>

    <div class="spacer"></div>
    <div>
    <label>Filename Template</label>
    </div>
    <div>
    @Html.TextBoxFor(m => Model.Surveys.OutputFileName, new { @class = "largetextbox" })
    </div>

    <div class="spacer"></div>

    <div>
    <label>Select Questions</label>
    </div>

    <div class="spacer"></div>
    
    <div id="questionlist">
    <table>
    <tr>
    <th>Select</th>
    <th>Required Answer</th>
    <th>Question</th>
    <th>Min Length</th>
    </tr>
    @{
        int questioncounter = 0;
        foreach (var item in Model.ListLeadStatQuestions)
        {
            <tr>
            <td>@Html.CheckBoxFor(m => Model.LeadStatQuestionsCheckboxes[questioncounter])</td>
            <td>
                @if (item.AnswerType == "C" && item.DropDown == true)
                {
                    <select name="LeadStatQuestionsAnswers[@(questioncounter.ToString())]">
                        <option value=""></option>
                        @foreach (var answeritems in item.AcceptedAnswerChar.Split(','))
                        {
                            <option value="@(answeritems)">@answeritems</option>
                        }
                     </select>
                }
                else if (item.AnswerType == "C")
                {
                    @Html.TextBoxFor(m => Model.LeadStatQuestionsAnswers[questioncounter])
                }
                else if (item.AnswerType == "I")
                {
                    @Html.TextBoxFor(m => Model.LeadStatQuestionsAnswers[questioncounter])
                }
                else if (item.AnswerType == "L")
                {
                    @Html.HiddenFor(m => Model.LeadStatQuestionsAnswers[questioncounter])
                }                
                @Html.HiddenFor(m => Model.LeadStatQuestionIDs[questioncounter])
                </td>
                <td>
                <label>@item.Question</label>
                </td>
                <td>
                @Html.TextBoxFor(m => Model.LeadStatQuestionsMinLength[questioncounter])
                </td>
            </tr>
            questioncounter++;
        }
    }
    </table>
    </div>

    <div class="spacer"></div>

    <input type="submit" value="Save Mapping" />
</fieldset>
}

<script type="text/javascript">
    $(document).ready(function () {

        $(".chosen").chosen();

        $("#LeadTemplatesID").change(function () {
            var ltID = $(this).val();
            window.location.href = "/Leads/CreateSurveyMapping?leadID=@(Model.Surveys.LeadID)&leadTemplateID=" + ltID;
        });

    });
</script>